import axios from 'axios'
import config from '@/config'

// request.get(url, { params })
// request.post(url, body)
const { auth, api } = config

const request = axios.create({
  baseURL: api.server
})

request.interceptors.request.use((config) => {
  // config.headers[auth.token_name] = localStorage.getItem(auth.storage_name)
  config.headers[auth.token_name] = `Bear ${sessionStorage.getItem(TOKEN_NAME) || localStorage.getItem(TOKEN_NAME)}`

  return config
})

request.interceptors.response.use(
  response => ({
    data: response?.data || {},
    code: 'success',
  }),
  error => Promise.reject(error)
)

export default request;
